import java.util.Random;
import java.util.Scanner;

public class Test1 {
    public static void main(String[] args) {
        //1.生成中奖号码
        int[] arr = fun1();//123456 7
        //2.用户输入号码(红球+蓝球)
        int[] newarr = fun2();//654321 7 也算，只要存在即可
        //3.判断用户中奖情况
        int readcount=0;
        int bluecount=0;
        //判断红球
        for (int i = 0; i < newarr.length-1; i++) {
           int readnum= newarr[i];
            for (int j = 0; j < arr.length-1; j++) {
                if(readnum==arr[j]){
                    readcount++;
                    break;
                }
            }
        }
        //判断蓝球
        int bluednum= newarr[newarr.length-1];
        if(bluednum==arr[arr.length-1]){
            bluecount++;
        }


    }
    public static int[] fun2() {
        //用于用户购买的彩票号码
        int[] arr = new int[7];
        Scanner sc = new Scanner(System.in);
        for (int i = 0; i < 6; ) {
            System.out.println("请输入第" + (i + 1) + "个红球号码");
            int readnum = sc.nextInt();
            //要求红球在1-33之间,并且不重复才添加数组里面
            if (readnum >= 1 && readnum <= 33) {
                int flag = contains(arr, readnum);
                if (flag == 0) {
                    arr[i] = readnum;
                    i++;
                } else {
                    System.out.println("重复,请重新输入 ");
                }
            } else {
                System.out.println("当前红球超出范围");
            }
        }
        System.out.println("输入蓝球号码");
        while (true) {
            int bluenum = sc.nextInt();
            if (bluenum >= 1 && bluenum <= 16) {
                arr[arr.length - 1] = bluenum;
                break;
            } else {
                System.out.println("蓝球号码超出范围请重新输入");
            }
        }
        return arr;
    }

    public static int[] fun1() {
        // 1.6个红球,一个蓝球
        //红球不能重复,蓝球可以重复
        int[] arr = new int[7];
        Random r = new Random();
        for (int i = 0; i < 6; ) {
            //获取红球号码
            int readNum = r.nextInt(33) + 1;
            int flag = contains(arr, readNum);//保证红球不重复
            if (flag == 0) {
                arr[i] = readNum;
                i++;
            }
        }
        //获取蓝球号码
        //最后一个蓝球号码
        int bluenum = r.nextInt(16) + 1;
        arr[arr.length - 1] = bluenum;
        return arr;
    }

    public static int contains(int[] arr, int Num) {
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] == Num) {
                return 1;
            }
        }
        return 0;
    }
}
